from pyecharts import options as opts
from pyecharts.charts import Bar

# 数据
values = [282, 170, 572, 398, 48]
categories = ["专科以下", "专科", "本科", "硕士研究生", "博士研究生"]

# 创建条形图
bar = (
    Bar(init_opts=opts.InitOpts(bg_color="#1D244A"))
    .add_xaxis(categories)
    .add_yaxis("", values, category_gap="50%", color="#7AD5FE")
    .reversal_axis()
    .set_global_opts(
        title_opts=opts.TitleOpts(title="学历", pos_left="center",
                                  title_textstyle_opts=opts.TextStyleOpts(color="white")),
        xaxis_opts=opts.AxisOpts(
            axislabel_opts=opts.LabelOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False)
        ),
        yaxis_opts=opts.AxisOpts(
            axislabel_opts=opts.LabelOpts(color="white"),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False)
        ),
        legend_opts=opts.LegendOpts(is_show=False),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(position="right", color="white", formatter="{c}")
    )
)

bar.render("xueli.html")
